﻿<%@ Page Title="发送短信" Language="C#" MasterPageFile="~/Web/BizWeb.Master" AutoEventWireup="true"
    CodeBehind="SmsMessageSend.aspx.cs" Inherits="Slja.WEB.WebUI.SmsMessageSend" %>

<%@ Import Namespace="Slja.BLL" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
 <%--   <script type="text/javascript" src="/js/jquery.js"></script>--%>
    <link type="text/css" href="../../Js/InputSelect/search_suggest.css" rel="stylesheet"
        charset="gb2312" />
    <script type="text/javascript" src="../../Js/InputSelect/search_suggest.js" charset="gb2312"></script>
    <script type="text/javascript" src="../../Js/Offen/public.js"></script>
    <script type="text/javascript" src="../../JS/jquery.xml2json.pack.js"></script>
     <script type="text/javascript" src="../../JS/Origine/DnmcTable.js"></script>
    <script type="text/javascript">

        var timer1, timer2;
        var Couter = 0;
        function ShowSendStatus() {
            var ids = $.trim($("#ctl00_ContentPlaceHolder1_hdfSentMsgIDs").val());
            var lbStatus = $("#ctl00_ContentPlaceHolder1_lbStatus");
            Couter++;
            if (Couter > 300) {
                timer1 = window.clearInterval(timer1); //情况timer1
                lbStatus.html("获取状态失败！")
                return;
            }

            if (ids !== "" && ids !== "0") {
                var statusList = Slja.WEB.WebUI.SmsMessageSend.GetMsgSendStatus(ids).value;
                var nSuccess = 0;
                var nError = 0;
                var sErrorNO = "";
                for (var i = 0; i < statusList.length; i++) {
                    //这些ID的数据行，若SendStatus出现2或3，则认为信息已经发送出。
                    if (statusList[i].Status == 1 || statusList[i].Status == 0) {
                        break;
                    } else {
                       // debugger;
                        if (timer1) {
                            timer1 = window.clearInterval(timer1); //情况timer1
                        }
                        nSuccess = nSuccess + (statusList[i].Status == 2 ? 1 : 0);
                        nError = nError + (statusList[i].Status == 3 ? 1 : 0);
                        sErrorNO += (statusList[i].Status == 3 ? (statusList[i].RecvNO + ",") : "");
                    }
                } //for
                if (!timer1) {
                    var str = "成功发送" + nSuccess + "条";
                    if (nError > 0) {
                        str += ",失败" + nError + "条(" + sErrorNO.substr(0, sErrorNO.length - 1) + ")。";
                    }
                    lbStatus.html(str); //状态
                } else {
                    lbStatus.html(lbStatus.html() + "."); //状态
                }
            } //if

        }
        function RecvNewMsg() {
            var tbx = $("#ctl00_ContentPlaceHolder1_tbxDownMsg");
            var arr = Slja.WEB.WebUI.SmsMessageSend.GetMsgReciving().value;
            var str = "";
            if (arr && arr.length > 0) {
                //tbx.val("");
                for (var i = 0; i < arr.length; i++) {
                    str += arr[i].ID + " ";
                    str += arr[i].SendNO + " ";
                    str += arr[i].MsgContent + " ";
                    str += arr[i].RecvTime + " ";
                    str += "\n";
                }
                tbx.val(str);
            }
        }
        function CheckSendStatus() {
            timer1 = window.setInterval("ShowSendStatus()", 3000);
        }
        function SetRecivingMsg() {
            timer2 = window.setInterval("RecvNewMsg()", 5000);
        }
        $(function () {
            // SetRecivingMsg();
        })
    </script>
    <link type="text/css" rel="Stylesheet" href="/CSS/default/biz.css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:HiddenField runat="server" ID="hdfUserID"/>
    <FrameWorkWebControls:TabOptionWebControls ID="TabOptionWebControls1" runat="server">
        <FrameWorkWebControls:TabOptionItem ID="TabOptionItem1" runat="server" Tab_Name="发短信">
            <fieldset class="inputtbl">
            <table>
            <tr>
                <td>
                    <table border="0">
                        <tr>
                            <td>
                                接收人
                            </td>
                            <td>
                                <div id="mailcontainer">
                                    <div class="mailAddress" id="divreciver" onmouseup="mailto.focus();">
                                        <input type="text" id="mailto" class="noborder-input" size="6" style="border: 0;
                                            padding: 0;" />
                                        <input id="mailtoval" value="" type="hidden" />
                                        <input id="mailtoall" value="" type="hidden" runat="server" />
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                短消息
                            </td>
                            <td>
                                <asp:TextBox runat="server" CssClass="mailContent" ID="tbxContent" Height="100" TextMode="MultiLine"></asp:TextBox>
                            </td>
                        </tr>
                    </table>
                    <%-- <asp:TextBox runat="server" ID="tbxReciver" Width="300" Height="50" Text="13331102290" TextMode="MultiLine"></asp:TextBox>--%>
                </td>
                <td>
                    <asp:TextBox runat="server" ID="tbxDownMsg" Width="300" Height="150" TextMode="MultiLine"
                        Style="display: none;"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td align="center">
                    <asp:Label runat="server" ID="lbStatus"></asp:Label>
                    <asp:Button runat="server" ID="btnSend" Text="发送" OnClientClick="GetTelNos();" CssClass="btnblue1" />
                    <asp:HiddenField runat="server" ID="hdfSentMsgIDs" />
                </td>
                <td align="center">
                    <asp:Button runat="server" ID="btnRecive" Text="接收" Visible="false" />
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <asp:Button runat="server" ID="btnDisconnect" Text="断开" Visible="false" />
                </td>
            </tr>
        </table>
                <div runat="server" id="pnlMsgHide" style="display: none;">
                </div>
            </fieldset>
        </FrameWorkWebControls:TabOptionItem>
         <FrameWorkWebControls:TabOptionItem ID="TabOptionItem2" runat="server" Tab_Name="信息记录">
            <div class="secinfo inputtble" style="padding:5px 5px;"><table id="tblDnmcMsgIndex" cellpadding="0" cellspacing="0" border="0" id="MsgMain" style="width:450px;background-color:#fff;">
                <tr dname="tmplt" style="display: none;" ><td><div class="msgrecord">
                    <div class="head"><span class="h_name" dname="Reciver">梁宁</span>(<span class="msgcount" dname="MsgCount">5</span>)<a href="#" onclick="TransferMsgList(this);" rowid="%index%"><input type="hidden" dname="RecvNO"/><span>&gt;&gt;</span></a></div>
                    <div class="onemsg"><span dname="MsgContent">我的邮件已经发送…</span></div>
                    <div class="foottime" dname="SendTime">2012-5-28</div>
                    </div><div class="msglistcontain" rowid="%index%">
                            <table id="tblMsgList" class="innertbl" width="100%" cellpadding="0" cellspacing="0" border="0">
                                <tr dtag="tmplt" style="display:none;">
                                    <td width="10%"><span dtag="MsgType1"></span></td>
                                    <td align="right">
                                        <div class="msgbody" dtag="MsgContent"></div>
                                        <span dtag="Status"></span><span dtag="Dtm"></span>
                                    </td>                                   
                                    <td width="10%"><span dtag="MsgType2"></span></td>
                                </tr>
                            </table>
                            <input type="hidden" id="tblMsgListHdf" />
                        </div>
                    </td></tr>                    
            </table>
            <input type="hidden" id="tblDnmcMsgIndexHdf" />
            </div>
         </FrameWorkWebControls:TabOptionItem>
      <%--   <FrameWorkWebControls:TabOptionItem  ID="TabOptionItem3" runat="server" Tab_Name="通讯录">
            <iframe src="Linkman.aspx" frameborder="0" style="width:100%;height:300px;"></iframe>
         </FrameWorkWebControls:TabOptionItem>
--%>
    </FrameWorkWebControls:TabOptionWebControls>
    
    <script type="text/javascript">
        var PreId = "#ctl00_ContentPlaceHolder1_";
        $(function () {
            //初始化发短信的tab页
            var options = {};
            options.selectedCallback = SelectedCallback;
            options.inputhide = true;
            options.width = $("#divreciver")[0].offsetWidth;
            options.whenClickShow = false;
            $("#mailcontainer").suggestShow($("#mailto"), $("#mailtoval"), "/web/ServiceHandler/search.ashx?type=LinkMan&LinkManType=<%=LinkManType.None %>&LinkManInfoClass=<%=LinkManInfoClass.lkmMobileTel %>", "", 1, 0, 0, "", options);

            //初始化短信记录tab页
            var tabMsgList = $("#tabLabel__1");
            if (tabMsgList.length > 0) {
                tabMsgList.click(function () {
                    InitMainTable();
                })
            }
        })
        function InitMainTable() {
            var usrID = $(PreId + "hdfUserID").val();
            var msgIndexInfo = Slja.WEB.WebUI.SmsMessageSend.GetXmlFromMsgIndexInfo(usrID).value;
            $("#tblDnmcMsgIndexHdf").val(msgIndexInfo);
            var mOpt = {};
            mOpt.align = "left";
            var dnmcTMain = new DnmcTable("tblDnmcMsgIndex", "", '#', mOpt, "dname");
            DnmcTable.Ini(dnmcTMain);
        }
        function TransferMsgList(obj) {
            var rowid = $(obj).attr("rowid");
            var cntn = $("div[class=msglistcontain][rowid=" + rowid + "]");
            var dtag="dtag";
            if ($("span", obj).text() === ">>") {
                cntn.show();
                //如果已经产生DataRow,则返回。
                if ($("#tblMsgList tr[" + dtag + "=DataRow]", cntn).length > 0) {return;}
                var usrID = $(PreId + "hdfUserID").val();
                var MobileNO = $("input[dname =RecvNO]", obj).val();
                var msgListInfo = Slja.WEB.WebUI.SmsMessageSend.GetXmlFromLinkmanMobileNO(usrID, MobileNO).value;
                var rowid = $(obj).attr("rowid");
                var cntn = $("div[class=msglistcontain][rowid=" + rowid + "]");
                $("#tblMsgListHdf", cntn).val(msgListInfo);
                var mOpt = {};
                mOpt.align = "left";
                mOpt.region = cntn;
                var dnmcLMain = new DnmcTable("tblMsgList", "", '#', mOpt, dtag);
                DnmcTable.Ini(dnmcLMain);
                $("span", obj).text("<<");
            } else {
                cntn.hide();
                $("span", obj).text(">>");
            }
            
        }
        function SelectedCallback(text, value) {           
            var inputs = $("input[name=mailoneInput]", "#divreciver");
            var has = false;
            inputs.each(function () {
                if ($(this).val().indexOf(value) > -1) {
                    has = true;                   
                    return false; //break;
                }
            })
            if (has) { $("#mailto").val(""); return; } //若号码已经存在，则返回
            var objhtml = CreateSelectedItem(text);           
            $(objhtml).insertBefore("#mailto");
            $("#mailto").val("");
        }
        function GetTelNos() {
            var telnoall = $("input[id$=mailtoall]");
            var inputs = $("input[name=mailoneInput]", "#divreciver");
            var strNOs = "";
            var strone = "";
            inputs.each(function () {
                strone = MachTelNO($(this).val());
                if (strNOs === "") {
                    strNOs = strone;
                } else {
                    if (strone) {
                        strNOs = strNOs + ';' + strone;
                    }
                }
            })
            telnoall.val(strNOs);
        }
        function MachTelNO(str) {
            var mat = str.match(/(?:\[)\d+(?=\])/);
            if (mat) {
                var str = mat[0];
                str = str.substring(1, str.length);
                return str;
            } else {
                return "";
            }       
        }
    </script>
</asp:Content>
